home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE03 / INTERNAL / DATEFORM.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-06-09  |  4.4 KB  |  125 lines

  1. unit Dateform;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, Grids, Calendar, StdCtrls, Buttons;
  8.  
  9. type
  10.   TDateSelector = class(TForm)
  11.     Calendar1: TCalendar;
  12.     OKButton: TBitBtn;
  13.     CancelButton: TBitBtn;
  14.     HelpButton: TBitBtn;
  15.     Label1: TLabel;
  16.     procedure FormCreate(Sender: TObject);
  17.     procedure OKButtonClick(Sender: TObject);
  18.     procedure HelpButtonClick(Sender: TObject);
  19.   private
  20.     { Private declarations }
  21.   public
  22.     { Public declarations }
  23.   end;
  24.  
  25. procedure DateSelSetCaption (Caption: PChar); export;
  26. procedure DateSelSetHelpInfo (HelpFile: PChar; HelpContext: LongInt); export;
  27. function DateSelDialog (var TheDate: Integer): Bool; export;
  28.  
  29. var
  30.     DateSelector: TDateSelector;
  31.  
  32. implementation
  33.  
  34. {$R *.DFM}
  35.  
  36. const
  37.     CustomCaption: String = '';      { If empty, use designed-in value }
  38.     HelpFileName: PChar = Nil;       { If Nil, disable help button     }
  39.     dwHelpContext: LongInt = -1;     { Help context to call            }
  40.     iDate: Integer = 0;              { An invalid value until initted  }
  41.  
  42. {--------------------------------------------------------------}
  43. { Name:    FormCreate                                          }
  44. { Purpose: OnCreate handler for the form.  It sets a custom    }
  45. {          caption if one has been supplied and disables the   }
  46. {          Help buttom if we haven't got any help info.        }
  47. {--------------------------------------------------------------}
  48. procedure TDateSelector.FormCreate(Sender: TObject);
  49. begin
  50.     { Set custom caption if one has been supplied }
  51.     if CustomCaption <> '' then Caption := CustomCaption;
  52.  
  53.     { See if Help stuff set up.  If not, disable Help button }
  54.     if (HelpFileName = Nil) or (dwHelpContext = -1) then
  55.         HelpButton.Enabled := False;
  56. end;
  57.  
  58. {--------------------------------------------------------------}
  59. { Name:    OKButtonClick                                       }
  60. { Purpose: Shared event handler for OK/Cancel/Double-clicks    }
  61. {--------------------------------------------------------------}
  62. procedure TDateSelector.OKButtonClick(Sender: TObject);
  63. begin
  64.     { If this wasn't a Cancel, set the iDate global }
  65.     if Sender <> CancelButton then iDate := Calendar1.Day;
  66.     Close;
  67. end;
  68.  
  69. {--------------------------------------------------------------}
  70. { Name:    HelpButtonClick                                     }
  71. { Purpose: Invoke the Windows Help engine if Help clicked.     }
  72. {--------------------------------------------------------------}
  73. procedure TDateSelector.HelpButtonClick(Sender: TObject);
  74. begin
  75.     { Just call the Help Engine with the info we've been given }
  76.     WinHelp (Handle, HelpFileName, Help_Context, dwHelpContext);
  77. end;
  78.  
  79. {--------------------------------------------------------------}
  80. { Name:    DateSelSetCaption                                   }
  81. { Purpose: DLL Interface routine.  Sets up a custom caption.   }
  82. {--------------------------------------------------------------}
  83. procedure DateSelSetCaption (Caption: PChar);
  84. begin
  85.     { StrPas doesn't check for Nil strings, so watch it ! }
  86.     if Caption <> Nil then CustomCaption := StrPas (Caption);
  87. end;
  88.  
  89. {--------------------------------------------------------------}
  90. { Name:    DateSelSetHelpInfo                                  }
  91. { Purpose: DLL Interface routine.  Sets up help information.   }
  92. {--------------------------------------------------------------}
  93. procedure DateSelSetHelpInfo (HelpFile: PChar; HelpContext: LongInt);
  94. begin
  95.     { If we've previously been called, clear old string }
  96.     if HelpFileName <> Nil then StrDispose (HelpFileName);
  97.  
  98.     { Now set up the new stuff }
  99.     HelpFileName := StrNew (HelpFile);
  100.     dwHelpContext := HelpContext;
  101. end;
  102.  
  103. {--------------------------------------------------------------}
  104. { Name:    DateSelDialog                                       }
  105. { Purpose: DLL Interface routine.  Execute the actual dialog.  }
  106. {--------------------------------------------------------------}
  107. function DateSelDialog (var TheDate: Integer): Bool;
  108. begin
  109.     { no date selected yet }
  110.     iDate := 0;
  111.     { Create the form instance }
  112.     DateSelector := TDateSelector.Create (Application);
  113.     try
  114.         { Display the dialog }
  115.         DateSelector.ShowModal;
  116.     finally
  117.         { Destroy the form instance }
  118.         DateSelector.Free;
  119.         Result := iDate <> 0;
  120.         if Result then TheDate := iDate;
  121.     end;
  122. end;
  123.  
  124. end.
  125.